import 'package:ac/api/ac_urls.dart';
import 'package:ac/common/ac_common.dart';
import 'package:ac/common/ac_pv_manager.dart';
import 'package:ac/route/ac_route_pages.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../common/style.dart';
import 'ac_login_logic.dart';

class AcLoginPage extends StatelessWidget {
  final logic = Get.find<AcLoginLogic>();
  final state = Get.find<AcLoginLogic>().state;
  final TapGestureRecognizer _termsProtocolRecognizer = TapGestureRecognizer();
  final TapGestureRecognizer _privacyProtocolRecognizer =
      TapGestureRecognizer();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        width: 375.w,
        decoration: const BoxDecoration(
          image: DecorationImage(
            image: AssetImage("images/login_bg.png"),
            fit: BoxFit.fill,
          ),
        ),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.end,
          children: [
            _appleLoginBtn(),
            SizedBox(height: 32.h),
            _fastLoginBtn(),
            SizedBox(height: 46.h),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                GestureDetector(
                  onTap: logic.changeAgreeStatus,
                  child: Obx(() {
                    var image = state.checkAgreement.value
                        ? "images/check_status_yes.png"
                        : "images/check_status_no.png";
                    return Image.asset(
                      image,
                      width: 16.w,
                      height: 16.w,
                    );
                  }),
                ),
                SizedBox(width: 8.w),
                Text.rich(TextSpan(
                  children: [
                    TextSpan(
                      text: "By using our App you agree with our \n",
                      style: TextStyle(fontSize: 12.sp, color: Colors.white),
                    ),
                    TextSpan(
                      text: "Terms of Use",
                      style: TextStyle(
                        decoration: TextDecoration.underline,
                        fontSize: 12.sp,
                        color: const Color(0xffffbc60),
                      ),
                      recognizer: _termsProtocolRecognizer
                        ..onTap = () {
                          //打开用户协议
                          logic.openUserProtocol();
                        },
                    ),
                    TextSpan(
                      text: " and ",
                      style: TextStyle(fontSize: 12.sp, color: Colors.white),
                    ),
                    TextSpan(
                      text: "Privacy Policy",
                      style: TextStyle(
                        fontSize: 12.sp,
                        color: const Color(0xffffbc60),
                        decoration: TextDecoration.underline,
                      ),
                      recognizer: _privacyProtocolRecognizer
                        ..onTap = () {
                          //打开用户协议
                          logic.openPrivacyProtocol();
                        },
                    ),
                  ],
                )),
              ],
            ),
            SizedBox(
              height: 80.h,
            ),
          ],
        ),
      ),
    );
  }

  Widget _appleLoginBtn() {
    return GestureDetector(
      onTap: logic.appleLogin.debounce(),
      child: Container(
        width: 278.h,
        height: 54.h,
        alignment: Alignment.center,
        decoration: BoxDecoration(
          gradient: const LinearGradient(
            colors: [
              Color(0xFFFFC371),
              Color(0xFFFF5F6D),
            ],
          ),
          borderRadius: BorderRadius.circular(12.r),
        ),
        child: Stack(
          alignment: Alignment.centerLeft,
          children: [
            Positioned(
              left: 32.w,
              child: Image.asset(
                "images/login_apple.png",
                width: 24.w,
                height: 24.h,
              ),
            ),
            Align(
              alignment: Alignment.center,
              child: Text(
                "Sign in with Apple",
                style: TextStyle(fontSize: 16.sp, color: Colors.white),
              ),
            )
          ],
        ),
      ),
    );
  }

  Widget _fastLoginBtn() {
    return GestureDetector(
      onTap: logic.fastLogin.debounce(),
      child: Container(
        width: 278.h,
        height: 54.h,
        alignment: Alignment.center,
        decoration: BoxDecoration(
            color: Colors.white, borderRadius: BorderRadius.circular(12.r)),
        child: Stack(
          alignment: Alignment.centerLeft,
          children: [
            Positioned(
              left: 32.w,
              child: Image.asset(
                "images/login_fast.png",
                width: 24.w,
                height: 24.h,
              ),
            ),
            Align(
              alignment: Alignment.center,
              child: Text(
                "Fast Login",
                style: TextStyle(
                  fontSize: 16.sp,
                  color: textColorBlack,
                ),
              ),
            )
          ],
        ),
      ),
    );
  }

}
